package com.htu.hdfs;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class MakeDir {

	public static Configuration getConf(){
		Configuration conf = new Configuration();
		return conf;

	}
	public static FileSystem initHdfs(String hdfspath,Configuration conf) throws IOException,URISyntaxException{
		FileSystem fs = FileSystem.get(new URI(hdfspath), conf);
		return fs;
	}
	public static boolean doMakeDir(FileSystem fs, String dir) throws IllegalArgumentException, IOException{
		boolean result = fs.mkdirs(new Path (dir));
		return result;
	}
	
	public static void main(String[] args) throws IOException,
			URISyntaxException {
		//Configuration conf = new Configuration();
		//获取配置信息
		
         Configuration conf = getConf();
         //
		//String hdfsPath = "hdfs://localhost:9000";
         FileSystem hdfs = initHdfs(args[0],conf);
		//FileSystem hdfs = FileSystem.get(new URI(hdfspath), conf);

		//String newDir = "/hdfstest";

		boolean result = doMakeDir(hdfs,args[1]);
		if (result) {
			System.out.println("Success!");
		} else {
			System.out.println("Failed!");
		}
	}
}